﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QunYing.Common;

namespace Client
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
             Boolean createdNew; //返回是否赋予了使用线程的互斥体初始所属权
            System.Threading.Mutex instance = new System.Threading.Mutex(true, "睿美水族环境监测平台", out createdNew); //同步基元变量
            if (createdNew) //赋予了线程初始所属权，也就是首次使用互斥体
            {
                XtraMessageBox.AllowCustomLookAndFeel = true;
                DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.JZBlue).Assembly);
                DevExpress.Skins.SkinManager.EnableFormSkins();
                Client.NativeResources.ExeResource();
                string[] str = Environment.GetLogicalDrives();
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                Application.Run(new MainForm());
                instance.ReleaseMutex();
            }
            else
            {
                GlobalInfo.MsgBoxShowError("程序已经启动，请勿启动多个实例！");
                Application.Exit();
            }
           
        }

        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            Loger.Log.Error("程序发生错误："+e.Exception.Message);
            GlobalInfo.MsgBoxShowError("程序发生错误："+e.Exception.Message);
            //throw new NotImplementedException();
        }
    }
}
